<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        <input type="text" id="search"> <button type="button" id="btn">搜索</button>
    </div>

    <script>
        let input1 = document.querySelector("#search");
        let btn = document.querySelector("#btn");

        function search(textValue){
            alert("搜索 "+textValue)
        }
        btn.onclick = function(){
            let t = input1.value;
            search(t);
        }
        input1.onkeydown=function(){
            let e = window.event || event;
            if(e.keyCode == 13){
                let t = input1.value;
                search(t);
            }
        }
    </script>
</body>
</html>